package com.lx.demo.sync.executor;

import com.lx.demo.context.ApplicationContextHolder;
import com.lx.demo.sync.base.ExtBaseDTO;
import com.lx.demo.valid.CheckDataIsNullService;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 基础同步器
 * @author wcy
 */
@Slf4j
@NoArgsConstructor
public class BaseSyncExecutor implements SyncExecutor {

    private CheckDataIsNullService checkDataIsNullService;

    private ExtSyncAbstract extSyncAbstract;


    public BaseSyncExecutor(ExtSyncAbstract extSyncAbstract) {
        this.extSyncAbstract = extSyncAbstract;
        checkDataIsNullService = ApplicationContextHolder.get().getBean(CheckDataIsNullService.class);
    }

    /**
     * 同步器同步方法
     * @param dataList
     */
    @Override
    public void executor(List<? extends ExtBaseDTO> dataList) {
        // 同时进入
        try {
            extSyncAbstract.bulkToDb(dataList);
        } catch (Exception e) {
            //重试
            log.error("save失败e={}", e);
        }
    }
}
